//
//  testChart.swift
//  AppCanPlugin
//
//  Created by CeriNo on 16/7/22.
//  Copyright © 2016年 zywx. All rights reserved.
//

import Foundation
import UIKit
import Charts

@objc class ChartTest :NSObject{
    class func run() -> Void {
        let delayTime = dispatch_time(DISPATCH_TIME_NOW, Int64(2 * Double(NSEC_PER_SEC)))
        dispatch_after(delayTime, dispatch_get_main_queue()) {
            self.addChart()
        }
    }
    
    
    private class func addChart () -> Void {
        guard let window = UIApplication.sharedApplication().keyWindow else{
            fatalError()
        }
        let chart = LineChartView()
        chart.backgroundColor = UIColor.grayColor();
        chart.frame = CGRectMake(0, 100, UIScreen.mainScreen().bounds.size.width, 300)
        var yVals = [ChartDataEntry]()
        let range :UInt32 = 100
        for i in 0..<20 {
            yVals.append(ChartDataEntry(value: Double(arc4random_uniform(range)), xIndex: i))
        }
        chart.data = LineChartData(xVals: (0..<20).flatMap{String($0+2000)}, dataSets: [LineChartDataSet(yVals: yVals, label: "Label")])
        window.addSubview(chart)
        
    }
}